Skip to content

Avoid unnecessary conversions between model.Metric and labels.Labels #6710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025

Conversation

damnever
Copy link
Contributor

What this PR does:

Remove complex conversions when selecting only series: LabelAdapters -> model.Metric(map) -> labels.Labels.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great change. Have you tried to benchmark it and see how much it helps?

@damnever
Copy link
Contributor Author

@yeya24 I haven't conducted a benchmark

@damnever
Copy link
Contributor Author

Not a serious benchmark, but the latency decreases by ~17% when I query 700k series manually.. I also slightly modified this benchmark, which has shown some improvements.

-                               assert.Contains(b, []int{numIngesters, numIngesters - 1}, countMockIngestersCalls(ingesters, "MetricsForLabelMatchers"))
-                               assert.Equal(b, numSeriesPerRequest, len(metrics))
+                               // assert.Contains(b, []int{numIngesters, numIngesters - 1}, countMockIngestersCalls(ingesters, "MetricsForLabelMatchers"))
+                               // assert.Equal(b, numSeriesPerRequest, len(metrics))
+                               _ = ingesters
+                               seriesSet := series.MetricsToSeriesSet(ctx, false, metrics)
+                               for seriesSet.Next() {
+                                       _ = seriesSet.At()
+                               }
old.txt:5: missing iteration count
old.txt:6: missing iteration count
../cortex/new.txt:5: missing iteration count
../cortex/new.txt:6: missing iteration count
goos: darwin
goarch: arm64
pkg: github.com/cortexproject/cortex/pkg/distributor
cpu: Apple M4 Pro
                                                                │   old.txt   │      ../cortex/new.txt       │
                                                                │   sec/op    │   sec/op     vs base         │
Distributor_MetricsForLabelMatchers/get_series_within_limits-14   280.5µ ± 0%   210.6µ ± 1%  -24.93% (n=100)

                                                                │   old.txt    │       ../cortex/new.txt       │
                                                                │     B/op     │     B/op      vs base         │
Distributor_MetricsForLabelMatchers/get_series_within_limits-14   856.3Ki ± 0%   573.7Ki ± 0%  -33.01% (n=100)

                                                                │   old.txt    │      ../cortex/new.txt       │
                                                                │  allocs/op   │  allocs/op   vs base         │
Distributor_MetricsForLabelMatchers/get_series_within_limits-14   11.090k ± 0%   9.107k ± 0%  -17.88% (n=100)

Copy link
Contributor

@danielblando danielblando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thanks

@danielblando danielblando merged commit 4bec60c into cortexproject:master Apr 24, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants